function getIdVideoArray(){
	var arr=[];
	$('.videoplscn').each(function(i,o){
		arr.push($(this).attr('rel'));
	});
	return arr;
}

function turnOFFdisplayButton(){
	var idArr = getIdVideoArray();
	
	for(var i=0 ; i<idArr.length; i++){
		jwplayer('container_'+idArr[i]).getPlugin("display").hide();
		jwplayer('container_'+idArr[i]).getPlugin("controlbar").hide();
	}
	return ;	
}

function doPlayVideo(id){
	var idArr = getIdVideoArray();
	for(var i=0 ; i<idArr.length; i++){
		if(id != idArr[i]){
			jwplayer('container_'+idArr[i]).pause(true);
		}
	}
	jwplayer('container_'+id).play(true);
}

function doPauseVideo(id){
	jwplayer('container_'+id).pause(true);
}

function doMinVolumn(id){
	jwplayer('container_'+id).setVolume(0);
	$( ".cls-btn-range-volumn[rel="+id+"]" ).slider( "option", "value", 0 );
}

function doMaxVolumn(id){
	jwplayer('container_'+id).setVolume(100);
	$( ".cls-btn-range-volumn[rel="+id+"]" ).slider( "option", "value", 100 );
} 

function doChangeVolumn(id){
}

function convertTime(duration){
	var h = parseInt(duration/3600);
	var m = parseInt( (duration-3600*h)/60);
	var s = parseInt( duration - 3600*h - 60*m );
	
	var str = '';
	if(h!=0){
		h = (h<9)?'0'+h:h;
		str = h+':';
		m = (m<9)?'0'+m:m;
	}
	s = (s<9)?'0'+s:s;
	
	str += m+':'+s;
	return str;
}

function videoPlaying(id,oldState){
	window.setInterval(function(){showVideoPlayingInfo(id)},1000);
}

function showVideoPlayingInfo(id){
	if( jwplayer('container_'+id).getState() == 'PLAYING' ){
		var current = jwplayer('container_'+id).getPosition();
		var duration = getVideoDuration(id);
		
		var timerShow = convertTime(current)+'/'+convertTime(duration);
		$('.cls-timer-display[rel='+id+']').text(timerShow);
		
		var gotoPos = (current/duration)*100;
		$( ".cls-range-buffer-play[rel="+id+"]" ).slider( "option", "value", gotoPos );
	}
}

function getVideoDuration(id){
	return jwplayer('container_'+id).getDuration();
}

function doToggleController(id){
	if($('.cls-wrap-video-control[rel='+id+']').css('display') == 'none'){
		$('.cls-wrap-context1-controller[rel='+id+']').hide();
		$('.cls-wrap-video-control[rel='+id+']').css({'display':'block'});
	}	
	else if($('.cls-wrap-video-control[rel='+id+']').css('display') == 'block'){
		$('.cls-wrap-context1-controller[rel='+id+']').show();
		$('.cls-wrap-video-control[rel='+id+']').css({'display':'none'});
	}	
}

$(document).ready(function(){
	
	$( ".cls-btn-range-volumn").slider({
		range: false,
		min: 0,
		max: 100,
		value: 70,
		slide: function( event, ui ) {
			var id = $(this).attr('rel');
			jwplayer('container_'+id).setVolume( ui.value);
		},
		stop: function(event, ui) { 
			var id = $(this).attr('rel');
			jwplayer('container_'+id).setVolume( ui.value);			
		}
	});
	
	
	$( ".cls-range-buffer-play").slider({
		range: false,
		min: 0,
		max: 100,
		value: 0,
		slide: function( event, ui ) {
			var id = $(this).attr('rel');
			var position = parseInt( (ui.value /100) * getVideoDuration(id) );
			jwplayer('container_'+id).seek(position);
		},
		stop: function(event, ui) { 
			var id = $(this).attr('rel');
			var position = parseInt( (ui.value /100) * getVideoDuration(id) );
			jwplayer('container_'+id).seek(position);	
		}
	});
});